package com.topInterview;

/**
 * @Author: huangzhigao
 * @Date: 2022/2/20 16:44
 */
public class Leecode75_Color {
    public void sortColors(int[] nums) {
        int left = -1;
        int index = 0;
        int right = nums.length;
        while (index < right) {
            if (nums[index] == 1) {
                index++;
            } else if (nums[index] == 0) {
                swap(nums, ++left, index++);
            } else {
                swap(nums, index, --right);
            }
        }


    }

    public void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    public static void main(String[] args) {
        int[] res = {2, 0, 2, 1, 1, 0};
        Leecode75_Color leecode75_color = new Leecode75_Color();
        leecode75_color.sortColors(res);
    }
}
